import re

filepath = "/workspace/comfyui/ComfyUI/custom_nodes/comfyui-manager/glob/manager_util.py"

with open(filepath, "r", encoding="utf-8") as f:
    content = f.read()

pattern = r"(?s)async def get_data_with_cache\(.*?\):.*?return json_obj"
replacement = '''
async def get_data_with_cache(uri, silent=False, cache_mode=True, dont_wait=False, dont_cache=False):
    cache_uri = get_cache_path(uri)

    # 离线模式：强制只读取本地缓存
    if os.path.exists(cache_uri):
        if not silent:
            print(f"[ComfyUI-Manager] 离线模式 - 使用本地缓存: {cache_uri}")
        return await get_data(cache_uri, silent=silent)

    logging.warning(f"[ComfyUI-Manager] 离线模式 - 本地缓存不存在: {cache_uri}，跳过远程拉取: {uri}")
    return {}
'''

new_content = re.sub(pattern, replacement.strip(), content)

with open(filepath, "w", encoding="utf-8") as f:
    f.write(new_content)

print("✅ 已成功将 ComfyUI-Manager 修改为完全离线模式。")
